package com.example.moshudriver.activity;



import java.math.BigDecimal;
import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.text.Editable;
import android.text.Selection;
import android.text.Spannable;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.BeeFramework.Utils.AnimationUtil;
import com.BeeFramework.Utils.TimeUtil;
import com.BeeFramework.Utils.Utils;
import com.BeeFramework.activity.BaseActivity;
import com.BeeFramework.model.BusinessResponse;
import com.BeeFramework.view.MyDialog;
import com.BeeFramework.view.MyProgressDialog;
import com.BeeFramework.view.RoundedWebImageView;
import com.BeeFramework.view.ToastView;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.location.LocationManagerProxy;
import com.amap.api.location.LocationProviderProxy;
import com.amap.api.maps.overlay.DrivingRouteOverlay;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.route.BusRouteResult;
import com.amap.api.services.route.DrivePath;
import com.amap.api.services.route.DriveRouteResult;
import com.amap.api.services.route.RouteSearch;
import com.amap.api.services.route.RouteSearch.DriveRouteQuery;
import com.amap.api.services.route.RouteSearch.OnRouteSearchListener;
import com.amap.api.services.route.WalkRouteResult;



import com.sgr.dykdriver.R;
import com.example.moshudriver.model.OrderInfoModel;
import com.example.moshudriver.protocol.ApiInterface;
import com.example.moshudriver.protocol.ENUM_ORDER_STATUS;
import com.example.moshudriver.protocol.ENUM_PAY_CODE;
import com.example.moshudriver.protocol.ORDER_INFO;
import com.example.moshudriver.protocol.SIMPLE_USER;
import com.example.moshudriver.protocol.orderacceptResponse;
import com.example.moshudriver.tools.LocationManager;
import com.example.moshudriver.tools.MessageConstant;
import com.example.moshudriver.tools.O2OMobile;
import com.example.moshudriver.tools.O2OMobileAppConst;
import com.example.moshudriver.tools.SESSION;
import com.example.moshudriver.utils.StringUtils;
import com.external.androidquery.callback.AjaxStatus;
import com.external.eventbus.EventBus;
import com.external.maxwin.view.IXListViewListener;
import com.external.maxwin.view.XListView;
import com.nostra13.universalimageloader.core.ImageLoader;

//查看我的订单详情
public class D1_OrderActivity extends BaseActivity implements BusinessResponse ,AMapLocationListener,OnRouteSearchListener,
	IXListViewListener {

	private AnimationDrawable mAnimationDrawable = null;
	private Dialog mPriceDialog;
	private Dialog mOrderDialog;
	private ImageView mBack;
	private TextView mTitle;
	private TextView mRightText;
	private XListView mXListView;
	private View mHeaderView;
	private Button mOrderBtnCancel;
	private Button mOrderBtnOk;
	private ImageView mOrderEmptyView;
	private RoundedWebImageView mOrderEmployerAvatar;
	private TextView mOrderEmployerName;
	private ImageView mOrderEmployerPhone;
	private TextView mOrderTime;
	private TextView mOrderSn;
	private TextView order_type;
	private TextView mOrderAppointmentTime;
	private TextView mOrderLocation_start, mOrderLocation_end;
	private TextView mOrderPrice;
	private LinearLayout mOrderTransactionPriceView;
	private LinearLayout mEstimate_distance_view;
	private LinearLayout mReal_distance_view;
	private TextView mOrderTransactionPrice;
	private TextView mOrderContentText;
	// private LinearLayout mOrderContentVoiceView;
	// private ImageView mOrderContentVoiceIcon;
	// private TextView mOrderContentVoiceTime;
	private LinearLayout mOrderStatusView;
	private TextView mOrderStatus;
	private ImageView mOrderStatusArrow;
	private View mOrderVisibleButtonView;
	private LinearLayout mOrderWaitView;
	private TextView mOrderEmployeeCount;
	private LinearLayout mOrderEmployeeView;
	private RoundedWebImageView mOrderEmployeeAvatar;
	private TextView mOrderEmployeeName;
	private ImageView mOrderEmployeePhone;
	private LinearLayout mOrderCommentView;
	private View mOrderPlay;
	private LinearLayout mOrderPlayOrderView;
	private TextView mOrderPlayOrderSn;
	private TextView mOrderPlayOrderServiceType;
	private TextView mOrderPlayOrderLocation;
	private TextView mOrderPlayOrderPrice;
	private LinearLayout mOrderPlayButtonView;
	private Button mOrderPlayOnline;
	private Button mOrderPlayOffline;
	private Button mOrderPlayCancel;
	private TextView mOrderPriceDialogPrice,
			order_price_dialog_distance;// 地图导航
	private EditText mOrderPriceDialogChangePrice;
	private Button mOrderPriceDialogOk;
	private Button mOrderPriceDialogCancel;
	protected ImageLoader mImageLoader = ImageLoader.getInstance();
	private OrderInfoModel mOrderInfoModel;
	private int mOrderId;
	public static String ORDER_ID = "orderId";
	// private MediaPlayer mPlayer;
	private int mWidthPixels; // 屏幕宽度
	private ENUM_PAY_CODE payCode;
	public int COMMENT_SEND = 1;
	private int PLAY_VOICE = 1;
	private TextView mAcceptOrderTime;
	public static boolean isForeground = false;// 是否在后台
	public static final String MESSAGE_RECEIVED_ACTION_TITLE = "com.example.title.MESSAGE_RECEIVED_ACTION";
	private MessageReceiver mMessageReceiver;
	public static boolean isfinsh_order = false;// 是否在后台
	public static boolean isNav = false;// 是点击导航
	public static boolean isFinsh = false;// 是点击完成
	public LocationManagerProxy mLocationManagerProxy;// 定位类
	private DriveRouteResult driveRouteResult;// 驾车模式查询结果
	private RouteSearch routeSearch;
	public static LatLonPoint startPoint, endPoint;// 起点坐标或者终点坐标
	// private ProgressDialog mRouteCalculatorProgressDialog;// 路径规划过程显示状态
	private SharedPreferences mShared1;
	private SharedPreferences.Editor mEditor1;

	private MyProgressDialog pro;
	float distant;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.d1_order_listview);

		// ttsManager = TTSController.getInstance(this);
		// ttsManager.init();
		// AMapNavi.getInstance(this).setAMapNaviListener(ttsManager);
		mShared1 = this.getSharedPreferences(O2OMobileAppConst.LOCATION_CHARGE,
				0);// 位置计费表
		mEditor1 = mShared1.edit();
		registerMessageReceiver(); // used for receive msg


		mBack = (ImageView) findViewById(R.id.top_view_back);
		mBack.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		mTitle = (TextView) findViewById(R.id.top_view_title);
		mRightText = (TextView) findViewById(R.id.top_view_right_text);

		// 设置标题
		mTitle.setText(getString(R.string.order_detail));
		mRightText.setVisibility(View.VISIBLE);
		// 获得屏幕的分辨率
		DisplayMetrics dm = getResources().getDisplayMetrics();
		mWidthPixels = dm.widthPixels;

		Intent intent = getIntent();
		mOrderId = intent.getIntExtra(ORDER_ID, 0);
		
		routeSearch = new RouteSearch(this);
		routeSearch.setRouteSearchListener(this);
		

		mHeaderView = LayoutInflater.from(this)
				.inflate(R.layout.d1_order, null);
		mXListView = (XListView) findViewById(R.id.order_listview);
		mXListView.addHeaderView(mHeaderView);
		mXListView.setPullLoadEnable(false);
		mXListView.loadMoreHide();
		mXListView.setRefreshTime();
		mXListView.setXListViewListener(this, 1);
		mXListView.setAdapter(null);

		mOrderBtnCancel = (Button) findViewById(R.id.order_button_cancel);
		mOrderBtnOk = (Button) findViewById(R.id.order_button_ok);
		mOrderEmptyView = (ImageView) findViewById(R.id.order_empty_view);

		mOrderPlay = findViewById(R.id.order_play);
		mOrderPlayOrderView = (LinearLayout) findViewById(R.id.order_play_order_view);
		mOrderPlayOrderSn = (TextView) findViewById(R.id.order_play_order_sn);
		mOrderPlayOrderServiceType = (TextView) findViewById(R.id.order_play_order_service_type);
		mOrderPlayOrderLocation = (TextView) findViewById(R.id.order_play_order_location);
		mOrderPlayOrderPrice = (TextView) findViewById(R.id.order_play_order_price);
		mOrderPlayButtonView = (LinearLayout) findViewById(R.id.order_play_button_view);
		mOrderPlayOnline = (Button) findViewById(R.id.order_play_online);
		mOrderPlayOffline = (Button) findViewById(R.id.order_play_offline);
		mOrderPlayCancel = (Button) findViewById(R.id.order_play_cancel);

		mOrderEmployerAvatar = (RoundedWebImageView) mHeaderView
				.findViewById(R.id.order_employer_avatar);
		mOrderEmployerName = (TextView) mHeaderView
				.findViewById(R.id.order_employer_name);
		mOrderEmployerPhone = (ImageView) mHeaderView
				.findViewById(R.id.order_employer_phone);
		mOrderTime = (TextView) mHeaderView.findViewById(R.id.order_time);
		mOrderSn = (TextView) mHeaderView.findViewById(R.id.order_sn);
		// mOrderServiceType = (TextView) mHeaderView
		// .findViewById(R.id.order_service_type);
		mOrderAppointmentTime = (TextView) mHeaderView
				.findViewById(R.id.order_appointment_time);
		mOrderLocation_start = (TextView) mHeaderView
				.findViewById(R.id.order_location_start);
		mOrderLocation_end = (TextView) mHeaderView
				.findViewById(R.id.order_location_end);
		mOrderPrice = (TextView) mHeaderView.findViewById(R.id.order_price);

		mShow_payway = (LinearLayout) mHeaderView
				.findViewById(R.id.ll_show_payway);
		mPayway = (TextView) mHeaderView.findViewById(R.id.tv_pay_way);
		mOrderTransactionPriceView = (LinearLayout) mHeaderView
				.findViewById(R.id.order_transaction_price_view);
		mOrderTransactionPrice = (TextView) mHeaderView
				.findViewById(R.id.order_transaction_price);
		mOrderContentText = (TextView) mHeaderView
				.findViewById(R.id.order_content_text);

		// 估算距离
		mEstimate_distance_view = (LinearLayout) mHeaderView
				.findViewById(R.id.ll_estimate_distance_view);
		mEstimate_distance_view.setVisibility(View.GONE);
		mEstimate_distance = (TextView) mHeaderView
				.findViewById(R.id.estimate_distance);
		// 真实距离
		mReal_distance_view = (LinearLayout) mHeaderView
				.findViewById(R.id.ll_real_distance_view);
		mReal_distance_view.setVisibility(View.GONE);
		mReal_distance = (TextView) mHeaderView
				.findViewById(R.id.real_distance);
		// mOrderContentVoiceView = (LinearLayout) mHeaderView
		// .findViewById(R.id.order_content_voice_view);
		// mOrderContentVoiceIcon = (ImageView) mHeaderView
		// .findViewById(R.id.order_content_voice_icon);
		// mOrderContentVoiceTime = (TextView) mHeaderView
		// .findViewById(R.id.order_content_voice_time);
		mOrderStatusView = (LinearLayout) mHeaderView
				.findViewById(R.id.order_status_view);
		mOrderStatus = (TextView) mHeaderView.findViewById(R.id.order_status);
		mOrderStatusArrow = (ImageView) mHeaderView
				.findViewById(R.id.order_status_arrow);
		mOrderVisibleButtonView = mHeaderView
				.findViewById(R.id.order_visible_button_view);
		mOrderWaitView = (LinearLayout) mHeaderView
				.findViewById(R.id.order_wait_view);
		mOrderEmployeeCount = (TextView) mHeaderView
				.findViewById(R.id.order_employee_count);

		order_type = (TextView) mHeaderView.findViewById(R.id.order_type);

		mOrderEmployeeView = (LinearLayout) mHeaderView
				.findViewById(R.id.order_employee_view);
		mOrderEmployeeAvatar = (RoundedWebImageView) mHeaderView
				.findViewById(R.id.order_employee_avatar);
		mOrderEmployeeName = (TextView) mHeaderView
				.findViewById(R.id.order_employee_name);
		mOrderEmployeePhone = (ImageView) mHeaderView
				.findViewById(R.id.order_employee_phone);

		mOrderCommentView = (LinearLayout) mHeaderView
				.findViewById(R.id.order_comment_view);
		mAcceptOrderTime = (TextView) mHeaderView
				.findViewById(R.id.accept_order_time);
//		receiver_map = (TextView) mHeaderView.findViewById(R.id.receiver_map);

		// 投诉
		mRightText.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(D1_OrderActivity.this,
						G0_ReportActivity.class);
				intent.putExtra("orderId", mOrderId);
				startActivity(intent);
			}
		});
		mOrderEmptyView.setOnClickListener(null);
		mOrderPlayOrderView.setOnClickListener(null);
		// 付款
		mOrderPlay.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AnimationUtil.backAnimationFromBottom(mOrderPlayOrderView);
				mOrderPlayOrderView.setVisibility(View.GONE);
				AnimationUtil.backAnimation(mOrderPlayButtonView);
				mOrderPlayButtonView.setVisibility(View.GONE);
				Handler mHandler = new Handler() {
					@Override
					public void handleMessage(Message msg) {
						super.handleMessage(msg);
						mOrderPlay.setVisibility(View.GONE);
						mOrderBtnCancel.setVisibility(View.VISIBLE);
					}
				};
				mHandler.sendEmptyMessageDelayed(0, 200);
			}
		});

		mOrderPlayOnline.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				payCode = ENUM_PAY_CODE.PAY_ONLINE;
				mOrderInfoModel.pay(mOrderId, ENUM_PAY_CODE.PAY_ONLINE.value());

			}
		});

		mOrderPlayOffline.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				payCode = ENUM_PAY_CODE.PAY_OFFLINE;
				mOrderInfoModel.pay(mOrderId, ENUM_PAY_CODE.PAY_OFFLINE.value());
			}
		});
		// 取消订单
		mOrderPlayCancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AnimationUtil.backAnimationFromBottom(mOrderPlayOrderView);
				mOrderPlayOrderView.setVisibility(View.GONE);
				AnimationUtil.backAnimation(mOrderPlayButtonView);
				mOrderPlayButtonView.setVisibility(View.GONE);
				Handler mHandler = new Handler() {
					@Override
					public void handleMessage(Message msg) {
						super.handleMessage(msg);
						mOrderPlay.setVisibility(View.GONE);
						mOrderBtnCancel.setVisibility(View.VISIBLE);
					}
				};
				mHandler.sendEmptyMessageDelayed(0, 200);
			}

		});

		mOrderStatusView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(D1_OrderActivity.this,
						D2_OrderHistoryActivity.class);
				intent.putExtra("order_id", mOrderId);
				startActivity(intent);
			}
		});

		mOrderInfoModel = new OrderInfoModel(this);
		mOrderInfoModel.addResponseListener(this);
		mOrderInfoModel.get(mOrderId);

	}

	private void showOrderPriceDialog(String price, String distant) {
		Activity activity = D1_OrderActivity.this;
		while (activity.getParent() != null) {
			activity = activity.getParent();
		}

		LayoutInflater inflater = LayoutInflater.from(activity);
		View view = inflater.inflate(R.layout.d1_order_price_dialog, null);
		mPriceDialog = new Dialog(activity, R.style.dialog);
		mPriceDialog.setContentView(view);
		mPriceDialog.setCanceledOnTouchOutside(false);
		mPriceDialog.show();

		mOrderPriceDialogPrice = (TextView) view
				.findViewById(R.id.order_price_dialog_price);
		order_price_dialog_distance = (TextView) view
				.findViewById(R.id.order_price_dialog_distance);
		mOrderPriceDialogChangePrice = (EditText) view
				.findViewById(R.id.order_price_dialog_change_price);
		mOrderPriceDialogOk = (Button) view
				.findViewById(R.id.order_price_dialog_ok);
		mOrderPriceDialogCancel = (Button) view
				.findViewById(R.id.order_price_dialog_cancel);

		if (price != null) {
			// System.out.println("测试点price====="+price);
			mOrderPriceDialogPrice.setText(Utils.formatBalance(price));
		}
		if (distant != null) {
			order_price_dialog_distance.setText(Utils.formatBalance(distant)
					+ getString(R.string.distance));
		}

		mOrderPriceDialogChangePrice.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				// TODO Auto-generated method stub
				if (s.toString().length() > 0) {
					if (s.toString().substring(0, 1).equals(".")) {
						s = s.toString().substring(1, s.length());
						mOrderPriceDialogChangePrice.setText(s);
					}
				}
				if (s.toString().length() > 1) {
					if (s.toString().substring(0, 1).equals("0")) {
						if (!s.toString().substring(1, 2).equals(".")) {
							s = s.toString().substring(1, s.length());
							mOrderPriceDialogChangePrice.setText(s);
							CharSequence charSequencePirce = mOrderPriceDialogChangePrice
									.getText();
							if (charSequencePirce instanceof Spannable) {
								Spannable spanText = (Spannable) charSequencePirce;
								Selection.setSelection(spanText,
										charSequencePirce.length());
							}
						}
					}
				}
				boolean flag = false;
				for (int i = 0; i < s.toString().length() - 1; i++) {
					String getstr = s.toString().substring(i, i + 1);
					if (getstr.equals(".")) {
						flag = true;
						break;

					}
				}
				if (flag) {
					int i = s.toString().indexOf(".");
					if (s.toString().length() - 3 > i) {
						String getstr = s.toString().substring(0, i + 3);
						mOrderPriceDialogChangePrice.setText(getstr);
						CharSequence charSequencePirce = mOrderPriceDialogChangePrice
								.getText();
						if (charSequencePirce instanceof Spannable) {
							Spannable spanText = (Spannable) charSequencePirce;
							Selection.setSelection(spanText,
									charSequencePirce.length());
						}
					}
				}
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub
			}

			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub
			}
		});

		mOrderPriceDialogCancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mPriceDialog.dismiss();
				if (null != pro) {
					pro.dismiss();
				}
			}
		});

		mOrderPriceDialogOk.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mOrderInfoModel.done(mOrderId,
						mOrderPriceDialogChangePrice.getText().toString()
								.equals("") ? mOrderPriceDialogPrice.getText()
								.toString() : mOrderPriceDialogChangePrice
								.getText().toString(),
						D1_OrderActivity.this.distant + "");
				mPriceDialog.dismiss();
				if (null != pro) {
					pro.dismiss();

				}
			}
		});

	}

	// 接单之后弹出的窗口
	private void showOrderDialog(boolean isSucceed, orderacceptResponse response) {
		LayoutInflater inflater = LayoutInflater.from(D1_OrderActivity.this);
		View view = inflater.inflate(R.layout.d1_order_dialog, null);
		mOrderDialog = new Dialog(D1_OrderActivity.this, R.style.dialog);
		mOrderDialog.setContentView(view);
		mOrderDialog.setCanceledOnTouchOutside(false);
		mOrderDialog.show();

		Button order_dialog_button = (Button) view
				.findViewById(R.id.order_dialog_button);
		ImageView order_dialog_icon = (ImageView) view
				.findViewById(R.id.order_dialog_icon);
		TextView order_dialog_text = (TextView) view
				.findViewById(R.id.order_dialog_text);
		TextView order_dialog_error_text = (TextView) view
				.findViewById(R.id.order_dialog_error_text);

		if (isSucceed) {
			order_dialog_icon.setImageResource(R.drawable.b2_selected_icon);
			order_dialog_text
					.setText(getString(R.string.receive_order_success));
			order_dialog_text.setTextColor(Color.parseColor("#000000"));
		} else {
			order_dialog_icon.setImageResource(R.drawable.d3_failed);
			order_dialog_text.setText(getString(R.string.receive_order_fail));
			order_dialog_text.setTextColor(Color.parseColor("#f65858"));
			order_dialog_error_text.setText(response.error_desc);
		}

		order_dialog_button.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mOrderDialog.dismiss();
			}
		});
	}

	@Override
	public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status)
			throws JSONException {
		// TODO Auto-generated method stub
		mXListView.stopRefresh();
		if (url.endsWith(ApiInterface.ORDER_INFO)) {

			Message msg = new Message();
			msg.what = MessageConstant.RECEIVE_ORDER_PUSH;
			EventBus.getDefault().post(msg);

			if (jo != null) {
				mOrderEmptyView.setVisibility(View.GONE);
				mOrderEmptyView.setImageDrawable(null);
				mOrderEmptyView.setOnClickListener(null);
				setOrderDetailView(mOrderInfoModel.publicOrder);
			} else {
				mOrderEmptyView.setVisibility(View.VISIBLE);
				mOrderEmptyView.setImageResource(R.drawable.e7_no_connections);
				mOrderEmptyView.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						mOrderInfoModel.get(mOrderId);
					}
				});
			}
		} else if (url.endsWith(ApiInterface.ORDER_CANCEL)) {
			ToastView toast = new ToastView(D1_OrderActivity.this,
					getString(R.string.order_have_canceled));
			toast.setGravity(Gravity.CENTER, 0, 0);
			toast.show();
			setOrderDetailView(mOrderInfoModel.publicOrder);
			isfinsh_order = true;
			this.finish();
		} else if (url.endsWith(ApiInterface.ORDER_ACCEPT)) {
			orderacceptResponse response = new orderacceptResponse();
			response.fromJson(jo);
			if (response.succeed == 1) {
				showOrderDialog(true, response);// 接单成功,弹出成功按钮
			} else {
				showOrderDialog(false, response);
			}
			setOrderDetailView(mOrderInfoModel.publicOrder);// 接单之后的界面
		} else if (url.endsWith(ApiInterface.ORDER_WORK_DONE)) {
			setOrderDetailView(mOrderInfoModel.publicOrder);
		} else if (url.endsWith(ApiInterface.ORDER_PAY)) {

			if (payCode == ENUM_PAY_CODE.PAY_OFFLINE) {
				AnimationUtil.backAnimationFromBottom(mOrderPlayOrderView);
				mOrderPlayOrderView.setVisibility(View.GONE);
				AnimationUtil.backAnimation(mOrderPlayButtonView);
				mOrderPlayButtonView.setVisibility(View.GONE);
				Handler mHandler = new Handler() {
					@Override
					public void handleMessage(Message msg) {
						super.handleMessage(msg);
						mOrderPlay.setVisibility(View.GONE);
						mOrderBtnCancel.setVisibility(View.VISIBLE);
					}
				};
				mHandler.sendEmptyMessageDelayed(0, 200);
			} else {
				// Todo 在线支付
				ToastView toast = new ToastView(getApplicationContext(),
						getString(R.string.share_content));
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
			}

			setOrderDetailView(mOrderInfoModel.publicOrder);
		} else if (url.endsWith(ApiInterface.ORDER_CONFIRM_PAY)) {
			isfinsh_order = true;
			setOrderDetailView(mOrderInfoModel.publicOrder);
		}
	}

	// 设置每个状态的界面 比如客户发单，司机接单。。。。
	private void setOrderDetailView(final ORDER_INFO order) {
		setOrderDate(order);

		// 显示估算距离
		mEstimate_distance_view.setVisibility(View.VISIBLE);
		mEstimate_distance.setText(order.offer_distance.trim() + "公里");
		// 实际距离不显示
		mReal_distance_view.setVisibility(View.GONE);

		mOrderEmployeeView.setVisibility(View.VISIBLE);
		
		if(order.order_status == ENUM_ORDER_STATUS.OS_PUBLISHED.value()) {
            mOrderEmployeeView.setVisibility(View.GONE);
			// 接单
			if(order.employer.id != 0) {
				if(isEmp(order.employer)) {
					mOrderWaitView.setVisibility(View.VISIBLE);
					mOrderEmployeeCount.setText(order.push_number + "");
					mOrderBtnCancel.setText(getString(R.string.cancel_order));
					mOrderBtnCancel.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            final MyDialog myDialog = new MyDialog(D1_OrderActivity.this, getString(R.string.cacel_order_or_not));
                            myDialog.show();
                            myDialog.positive.setOnClickListener(new OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    // TODO Auto-generated method stub
                                    myDialog.dismiss();
                                    mOrderInfoModel.cancel(mOrderId);
                                }
                            });
                            myDialog.negative.setOnClickListener(new OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    // TODO Auto-generated method stub
                                    myDialog.dismiss();
                                }
                            });
                        }
                    });
				} else {
				
					mOrderBtnCancel.setText(getString(R.string.receive_immediately));
					mOrderBtnCancel.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            mOrderInfoModel.accept(mOrderId);
                        }
                    });
				}
			}
		} 
		
		
		// 已抢单，因此跳过接单状态
		if (order.order_status == ENUM_ORDER_STATUS.OS_ABOARD.value()) {
			// 已确认接单
			// backToast();
			mOrderWaitView.setVisibility(View.GONE);
			mOrderBtnCancel.setVisibility(View.GONE);

			if (isEmp(order.employer)) { // 雇主
				if (order.employee.id != 0) {
					setEmployee(order.employee, false, order);
				}
				mOrderBtnCancel.setEnabled(false);
				mOrderBtnCancel
						.setBackgroundResource(R.drawable.c1_applied_btn);
				mOrderBtnCancel.setText(getString(R.string.wait_for_complete));
			} else if (isEmp(order.employee)) { // 司机
				setEmployee(order.employee, true, order);
				mOrderBtnOk.setVisibility(View.VISIBLE);
				mOrderVisibleButtonView.setVisibility(View.VISIBLE);
				mOrderBtnOk.setText(getString(R.string.confirm_complete));
				mOrderBtnOk.setEnabled(true);
				mOrderBtnOk
						.setBackgroundResource(R.drawable.c1_apply_btn_select);
				mOrderBtnOk.setOnClickListener(new OnClickListener() {// 确认完成

							@Override
							public void onClick(View v) {
								//乘客上次的坐标
								endPoint = new LatLonPoint(order.location.lat,
										order.location.lon);
								
								
								//定位一次
								mLocationManagerProxy = LocationManagerProxy
										.getInstance(D1_OrderActivity.this);
								mLocationManagerProxy.setGpsEnable(false);
						
								mLocationManagerProxy.requestLocationData(
										LocationProviderProxy.AMapNetwork, -1,
										10, D1_OrderActivity.this);
								pro = new MyProgressDialog(
										D1_OrderActivity.this, "请稍候...");
								pro.show();
							}
						});

			} else { // 游客
				setVisitor();
			}

		}
		// else
		if (order.order_status == ENUM_ORDER_STATUS.OS_KNOCK_DOWN.value()) {
			// 已确认接单
			// backToast();
			mOrderWaitView.setVisibility(View.GONE);
			mOrderBtnCancel.setEnabled(true);
			mOrderBtnCancel
					.setBackgroundResource(R.drawable.c1_apply_btn_select);

			// 显示估算距离
			mEstimate_distance_view.setVisibility(View.VISIBLE);
			mEstimate_distance.setText(order.offer_distance.trim() + "公里");
			// 实际距离不显示
			mReal_distance_view.setVisibility(View.GONE);

		

			if (isEmp(order.employer)) { // 乘客

				if (order.employee.id != 0) {
					setEmployee(order.employee, false, order);
				}
				mOrderBtnCancel.setEnabled(false);
				mOrderBtnCancel
						.setBackgroundResource(R.drawable.c1_applied_btn);
				mOrderBtnCancel.setText(getString(R.string.wait_for_complete));
			} else if (isEmp(order.employee)) { // 司机
				setEmployee(order.employee, true, order);
				mOrderTransactionPrice.setVisibility(View.GONE);
				mOrderBtnOk.setVisibility(View.VISIBLE);
				mOrderVisibleButtonView.setVisibility(View.VISIBLE);
				mOrderBtnOk.setText(getString(R.string.receive_pass));
				mOrderBtnOk.setEnabled(false);
				mOrderBtnOk.setBackgroundResource(R.drawable.c1_applied_btn);
				mOrderBtnCancel.setVisibility(View.VISIBLE);
				mOrderBtnCancel.setText(getString(R.string.cancel_order));
				mOrderBtnCancel.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						final MyDialog myDialog = new MyDialog(
								D1_OrderActivity.this,
								getString(R.string.cacel_order_or_not));
						myDialog.show();
						myDialog.positive
								.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View v) {
										// TODO Auto-generated method stub
										myDialog.dismiss();
										mOrderInfoModel.cancel(mOrderId);
									}
								});
						myDialog.negative
								.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View v) {
										// TODO Auto-generated method stub
										myDialog.dismiss();
									}
								});
					}
				});
			} else { // 游客
				setVisitor();
			}

		} else if (order.order_status == ENUM_ORDER_STATUS.OS_WORK_DONE.value()) {
			// backToast();
			// 订单完成
			mOrderWaitView.setVisibility(View.GONE);

			// 不显示估算距离
			mEstimate_distance_view.setVisibility(View.GONE);
			// 实际距离显示
			mReal_distance_view.setVisibility(View.VISIBLE);
			mReal_distance.setText(order.transaction_distance.trim() + "公里");

			mOrderBtnCancel.setEnabled(true);
			mOrderBtnCancel
					.setBackgroundResource(R.drawable.c1_apply_btn_select);
			
			if (order.transaction_price != null
					&& !order.transaction_price.equals("")) {
				mOrderTransactionPrice.setText(Utils
						.formatBalance(order.transaction_price)
						+ getString(R.string.yuan));
			} else {
				mOrderTransactionPrice.setText(Utils
						.formatBalance(order.offer_price)
						+ getString(R.string.yuan));
			}
			if (isEmp(order.employer)) { // 乘客
				if (order.employee.id != 0) {
					setEmployee(order.employee, false, order);
				}
				mOrderBtnCancel.setText(getString(R.string.immediately_pay));
				mOrderBtnCancel.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						mOrderPlay.setVisibility(View.VISIBLE);
						mOrderPlayOrderView.setVisibility(View.VISIBLE);
						AnimationUtil.showAnimationFromTop(mOrderPlayOrderView);
						mOrderPlayButtonView.setVisibility(View.VISIBLE);
						AnimationUtil.showAnimation(mOrderPlayButtonView);
						mOrderBtnCancel.setVisibility(View.GONE);
						if (order.order_sn != null) {
							mOrderPlayOrderSn.setText(order.order_sn);
						}
						// if (order.service_type != null
						// && order.service_type.title != null) {
						// mOrderPlayOrderServiceType
						// .setText(order.service_type.title);
						// }
						if (order.location != null
								&& order.location.name != null) {
							mOrderPlayOrderLocation
									.setText(order.location.name);
						}
						mOrderPlayOrderPrice.setText(Utils
								.formatBalance(order.transaction_price)
								+ getString(R.string.yuan));
					}
				});
			} else if (isEmp(order.employee)) { // 司机
				setEmployee(order.employee, true, order);
				//乘客未付款之前交易金额不可见
				mOrderTransactionPriceView.setVisibility(View.GONE);

				mOrderBtnOk.setVisibility(View.GONE);
				mOrderVisibleButtonView.setVisibility(View.GONE);
				mOrderBtnCancel.setVisibility(View.VISIBLE);
				mOrderBtnCancel.setEnabled(false);
				mOrderBtnCancel
						.setBackgroundResource(R.drawable.c1_applied_btn);
				mOrderBtnCancel.setText(getString(R.string.wait_for_pay));
			} else { // 游客
				setVisitor();
			}
		} else if (order.order_status == ENUM_ORDER_STATUS.OS_PAYED.value()) {
			// backToast();
			// 已付费
			mOrderWaitView.setVisibility(View.GONE);
			mOrderBtnCancel.setEnabled(true);
			mOrderBtnCancel
					.setBackgroundResource(R.drawable.c1_apply_btn_select);
			mOrderTransactionPriceView.setVisibility(View.VISIBLE);

			// 不显示估算距离
			mEstimate_distance_view.setVisibility(View.GONE);
			// 实际距离显示
			mReal_distance_view.setVisibility(View.VISIBLE);
			mReal_distance.setText(order.transaction_distance.trim() + "公里");

			if (order.transaction_price != null
					&& !order.transaction_price.equals("")) {
				mOrderTransactionPrice.setText(Utils
						.formatBalance(order.transaction_price)
						+ getString(R.string.yuan));
			} else {
				mOrderTransactionPrice.setText(Utils
						.formatBalance(order.offer_price)
						+ getString(R.string.yuan));
			}
			if (isEmp(order.employer)) { // 乘客
				if (order.employee.id != 0) {
					setEmployee(order.employee, false, order);
				}
				mOrderBtnCancel.setEnabled(false);
				mOrderBtnCancel
						.setBackgroundResource(R.drawable.c1_applied_btn);
				mOrderBtnCancel
						.setText(getString(R.string.wait_for_confirm_pay));
			} else if (isEmp(order.employee)) { // 司机
				setEmployee(order.employee, true, order);
//				mOrderTransactionPriceView.setVisibility(View.GONE);
				mOrderBtnCancel.setText(getString(R.string.confirm_pay));
				mOrderBtnCancel.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						mOrderInfoModel.confirmPay(mOrderId);
					}
				});
			} else { // 游客
				setVisitor();
			}
		} else if (order.order_status == ENUM_ORDER_STATUS.OS_PAY_CONFORMED
				.value()) {
			isfinsh_order = true;
			// 该状态可以返回主界面了
			// back();
			showPayWay();

			// 不显示估算距离
			mEstimate_distance_view.setVisibility(View.GONE);
			// 实际距离显示
			mReal_distance_view.setVisibility(View.VISIBLE);
			mReal_distance.setText(order.transaction_distance.trim() + "公里");

			// 付款已确认
			mOrderWaitView.setVisibility(View.GONE);
			mOrderBtnCancel.setEnabled(true);
			mOrderBtnCancel
					.setBackgroundResource(R.drawable.c1_apply_btn_select);
			mOrderTransactionPriceView.setVisibility(View.VISIBLE);
			if (order.transaction_price != null
					&& !order.transaction_price.equals("")) {
				mOrderTransactionPrice.setText(Utils
						.formatBalance(order.transaction_price)
						+ getString(R.string.yuan));
			} else {
				mOrderTransactionPrice.setText(Utils
						.formatBalance(order.offer_price)
						+ getString(R.string.yuan));
			}
			if (isEmp(order.employer)) { // 司机
				if (order.employee.id != 0) {
					setEmployee(order.employee, false, order);
				}
				mOrderBtnCancel.setText(getString(R.string.evaluate_now));
				mOrderBtnCancel.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						// Toast.makeText(D1_OrderDetailActivity.this,
						// OrderStatusPayConformed, 0).show();
						Intent it = new Intent(D1_OrderActivity.this,
								D3_OrderCommentActivity.class);
						it.putExtra(O2OMobileAppConst.ORDERINFO, order);
						startActivityForResult(it, COMMENT_SEND);
					}
				});
			} else if (isEmp(order.employee)) { // 司机
				setEmployee(order.employee, true, order);
				mOrderBtnCancel.setText(getString(R.string.evaluate_now));
				mOrderBtnCancel.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Intent it = new Intent(D1_OrderActivity.this,
								D3_OrderCommentActivity.class);
						it.putExtra(O2OMobileAppConst.ORDERINFO, order);
						startActivityForResult(it, COMMENT_SEND);
					}
				});
			} else { // 游客
				setVisitor();
			}
		} else if (order.order_status == ENUM_ORDER_STATUS.OS_EMPLOYEE_COMMENTED
				.value()) {
			showPayWay();
			// 该状态可以返回主界面了
			// 不显示估算距离
			mEstimate_distance_view.setVisibility(View.GONE);
			// 实际距离显示
			mReal_distance_view.setVisibility(View.VISIBLE);
			mReal_distance.setText(order.transaction_distance.trim() + "公里");
			// 雇员已评
			mOrderWaitView.setVisibility(View.GONE);
			mOrderBtnCancel.setEnabled(true);
			mOrderBtnCancel
					.setBackgroundResource(R.drawable.c1_apply_btn_select);
			mOrderTransactionPriceView.setVisibility(View.VISIBLE);
			if (order.transaction_price != null
					&& !order.transaction_price.equals("")) {
				mOrderTransactionPrice.setText(Utils
						.formatBalance(order.transaction_price)
						+ getString(R.string.yuan));
			} else {
				mOrderTransactionPrice.setText(Utils
						.formatBalance(order.offer_price)
						+ getString(R.string.yuan));
			}
			mOrderCommentView.setVisibility(View.VISIBLE);
			mOrderCommentView.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent it = new Intent(D1_OrderActivity.this,
							D4_OrderCommentListActivity.class);
					it.putExtra(O2OMobileAppConst.ORDERINFO, order);
					startActivity(it);
				}
			});
			if (isEmp(order.employer)) { // 乘客
				if (order.employee.id != 0) {
					setEmployee(order.employee, false, order);
				}
				mOrderBtnCancel.setText(getString(R.string.evaluate_now));
				mOrderBtnCancel.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent it = new Intent(D1_OrderActivity.this,
								D3_OrderCommentActivity.class);
						it.putExtra(O2OMobileAppConst.ORDERINFO, order);
						startActivityForResult(it, COMMENT_SEND);
					}
				});
			} else if (isEmp(order.employee)) { // 司机
				setEmployee(order.employee, true, order);
				mOrderBtnCancel.setEnabled(false);
				mOrderBtnCancel
						.setBackgroundResource(R.drawable.c1_applied_btn);
				mOrderBtnCancel.setText(getString(R.string.wait_for_evaluate));
			} else { // 游客
				setVisitor();
			}
		} else if (order.order_status == ENUM_ORDER_STATUS.OS_EMPLOYER_COMMENTED
				.value()) {
			showPayWay();
			// 该状态可以返回主界面了
			// 不显示估算距离
			mEstimate_distance_view.setVisibility(View.GONE);
			// 实际距离显示
			mReal_distance_view.setVisibility(View.VISIBLE);
			mReal_distance.setText(order.transaction_distance.trim() + "公里");
			// 乘客已评
			mOrderWaitView.setVisibility(View.GONE);
			mOrderBtnCancel.setEnabled(true);
			mOrderBtnCancel
					.setBackgroundResource(R.drawable.c1_apply_btn_select);
			mOrderTransactionPriceView.setVisibility(View.VISIBLE);
			if (order.transaction_price != null
					&& !order.transaction_price.equals("")) {
				mOrderTransactionPrice.setText(Utils
						.formatBalance(order.transaction_price)
						+ getString(R.string.yuan));
			} else {
				mOrderTransactionPrice.setText(Utils
						.formatBalance(order.offer_price)
						+ getString(R.string.yuan));
			}
			mOrderCommentView.setVisibility(View.VISIBLE);
			mOrderCommentView.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent it = new Intent(D1_OrderActivity.this,
							D4_OrderCommentListActivity.class);
					it.putExtra(O2OMobileAppConst.ORDERINFO, order);
					startActivity(it);
				}
			});
			if (isEmp(order.employer)) { // 乘客
				if (order.employee.id != 0) {
					setEmployee(order.employee, false, order);
				}
				mOrderBtnCancel.setEnabled(false);
				mOrderBtnCancel
						.setBackgroundResource(R.drawable.c1_applied_btn);
				mOrderBtnCancel.setText(getString(R.string.wait_for_evaluate));
			} else if (isEmp(order.employee)) { // 司机
				setEmployee(order.employee, true, order);
				mOrderBtnCancel.setText(getString(R.string.evaluate_now));
				mOrderBtnCancel.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Intent it = new Intent(D1_OrderActivity.this,
								D3_OrderCommentActivity.class);
						it.putExtra(O2OMobileAppConst.ORDERINFO, order);
						startActivityForResult(it, COMMENT_SEND);
					}
				});
			} else { // 游客
				setVisitor();
			}
		} else if (order.order_status == ENUM_ORDER_STATUS.OS_FINISHED.value()) {
			showPayWay();
			// 该状态可以返回主界面了
			// 不显示估算距离
			mEstimate_distance_view.setVisibility(View.GONE);
			// 实际距离显示
			mReal_distance_view.setVisibility(View.VISIBLE);
			mReal_distance.setText(order.transaction_distance.trim() + "公里");
			// 订单结束
			mOrderWaitView.setVisibility(View.GONE);
			mOrderBtnCancel.setEnabled(true);
			mOrderBtnCancel
					.setBackgroundResource(R.drawable.c1_apply_btn_select);
			mOrderTransactionPriceView.setVisibility(View.VISIBLE);
			if (order.transaction_price != null
					&& !order.transaction_price.equals("")) {
				mOrderTransactionPrice.setText(Utils
						.formatBalance(order.transaction_price)
						+ getString(R.string.yuan));
			} else {
				mOrderTransactionPrice.setText(Utils
						.formatBalance(order.offer_price)
						+ getString(R.string.yuan));
			}
			mOrderCommentView.setVisibility(View.VISIBLE);
			mOrderCommentView.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent it = new Intent(D1_OrderActivity.this,
							D4_OrderCommentListActivity.class);
					it.putExtra(O2OMobileAppConst.ORDERINFO, order);
					startActivity(it);
				}
			});
			if (isEmp(order.employer)) { // 乘客
				if (order.employee.id != 0) {
					setEmployee(order.employee, false, order);
				}
				mOrderBtnCancel.setText(getString(R.string.share_evalute));
				mOrderBtnCancel.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent intent = new Intent(D1_OrderActivity.this,
								D3_OrderCommentCompleteActivity.class);
						intent.putExtra("order_id", mOrderId);
						startActivity(intent);
					}
				});
			} else if (isEmp(order.employee)) { // 司机
				setEmployee(order.employee, true, order);
				mOrderBtnCancel.setText(getString(R.string.share_evalute));
				mOrderBtnCancel.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent intent = new Intent(D1_OrderActivity.this,
								D3_OrderCommentCompleteActivity.class);
						intent.putExtra("order_id", mOrderId);
						startActivity(intent);
					}
				});
			} else { // 游客
				setVisitor();
			}
		} else if (order.order_status == ENUM_ORDER_STATUS.OS_CANCELED.value()) {
			// 订单取消状态也可以返回
			// 显示估算距离
			mEstimate_distance_view.setVisibility(View.VISIBLE);
			mEstimate_distance.setText(order.offer_distance.trim() + "公里");
			// 实际距离不显示
			mReal_distance_view.setVisibility(View.GONE);
			// 订单取消
			mOrderWaitView.setVisibility(View.GONE);
			if (isEmp(order.employer)) { // 乘客
				if (order.employee.id != 0) {
					setEmployee(order.employee, false, order);
				}
				mOrderBtnCancel.setEnabled(false);
				mOrderBtnCancel
						.setBackgroundResource(R.drawable.c1_applied_btn);
				mOrderBtnCancel
						.setText(getString(R.string.order_have_canceled));
			} else if (isEmp(order.employee)) { // 司机
				setEmployee(order.employee, true, order);
				mOrderBtnOk.setVisibility(View.GONE);
				mOrderVisibleButtonView.setVisibility(View.GONE);
				mOrderBtnCancel.setEnabled(false);
				mOrderBtnCancel
						.setBackgroundResource(R.drawable.c1_applied_btn);
				mOrderBtnCancel
						.setText(getString(R.string.order_have_canceled));
			} else { // 游客
				setVisitor();
			}
		}
	}

	private void showPayWay() {
		// TODO Auto-generated method stub
		mShow_payway.setVisibility(View.VISIBLE);
		if (mOrderInfoModel.publicOrder.pay_code == 0) {
			mPayway.setText("线上支付");
		} else {
			mPayway.setText("线下支付");
		}
	}

	/**
	 * 订单详情
	 * 
	 * @param order
	 */
	private void setOrderDate(final ORDER_INFO order) {
		if (order.employer != null && order.employer.avatar != null
				&& order.employer.avatar.thumb != null) {
			Log.i("employee", order.employer + "");
			mImageLoader.displayImage(order.employer.avatar.thumb,
					mOrderEmployerAvatar, O2OMobile.options_head);
		}
		// mOrderEmployerAvatar.setOnClickListener(new OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// // TODO Auto-generated method stub
		// Intent intent = new Intent(D1_OrderActivity.this,
		// F0_ProfileActivity.class);
		// intent.putExtra(F0_ProfileActivity.USER_ID, order.employer.id);
		// startActivity(intent);
		// }
		// });
		if (order.employer != null && order.employer.nickname != null) {
			mOrderEmployerName.setText(order.employer.nickname);
		}
		if (order.created_at != null) {
			mOrderTime.setText(TimeUtil.timeAgo(order.created_at));
		}
		if (order.order_sn != null) {
			mOrderSn.setText(order.order_sn);
		}
		if (order.service_type == 1) {

			order_type.setText(R.string.now_order);
		} else {
			// 预约打车
			order_type.setText(R.string.appoint_order);

		}
		if (order.appointment_time != null) {
			mOrderAppointmentTime.setText(order.appointment_time);
		}
		if (order.location != null && order.location.name != null) {
			mOrderLocation_start.setText(order.location.name);
		}
		if (order.location != null && order.location.name_end != null) {
			mOrderLocation_end.setText(order.location.name_end);
		}
		if (order.offer_price != null) {
			mOrderPrice.setText(Utils.formatBalance(order.offer_price)
					+ getString(R.string.yuan));
		}
		if (order.content != null && order.content.text != null
				&& !order.content.text.equals("")) {
			mOrderContentText.setText(order.content.text);
		}
		// if (order.content != null && order.content.voice != null) {
		// if (!order.content.voice.equals("")) {
		// mOrderContentVoiceView.setVisibility(View.VISIBLE);
		// mOrderContentVoiceTime.setText(order.duration + "'");
		//
		// LayoutParams layoutParams_icon = (LayoutParams)
		// mOrderContentVoiceView
		// .getLayoutParams();
		// layoutParams_icon.width = mWidthPixels / 6 + order.duration * 3;
		// layoutParams_icon.height = mWidthPixels / 12;
		// mOrderContentVoiceView.setLayoutParams(layoutParams_icon);
		//
		// }
		// mOrderContentVoiceView.setOnClickListener(new OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// // TODO Auto-generated method stub
		// if (mPlayer == null) {
		// mOrderContentVoiceIcon
		// .setImageResource(R.anim.voice_play_animation);
		// mAnimationDrawable = (AnimationDrawable) mOrderContentVoiceIcon
		// .getDrawable();
		// mAnimationDrawable.setOneShot(false);
		// mAnimationDrawable.start();
		//
		// Message msg = new Message();
		// msg.what = PLAY_VOICE;
		// msg.obj = order;
		// handler.sendMessage(msg);
		// } else {
		// mPlayer.release();
		// mPlayer = null;
		// mAnimationDrawable.stop();
		// mOrderContentVoiceIcon
		// .setImageResource(R.drawable.d8_btn_playing_2);
		// }
		// }
		// });
		// }
		mOrderStatus
				.setText(StringUtils.getOrderStatusName(order.order_status));
	}

	/**
	 * @param employee
	 *            司机
	 * @param isEmployee
	 *            如果是司机则显示乘客电话否则显示司机电话
	 */
	private void setEmployee(final SIMPLE_USER employee, boolean isEmployee,
			ORDER_INFO order) {
		if (!"".equals(order.accept_time)) {
			mAcceptOrderTime.setText(TimeUtil.timeAgo(order.accept_time));
		}
		if (employee != null && employee.avatar != null
				&& employee.avatar.thumb != null) {
			mImageLoader.displayImage(employee.avatar.thumb,
					mOrderEmployeeAvatar, O2OMobile.options_head);
		}
		// mOrderEmployeeAvatar.setOnClickListener(new OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// // TODO Auto-generated method stub
		// Intent intent = new Intent(D1_OrderActivity.this,
		// F0_ProfileActivity.class);
		// intent.putExtra(F0_ProfileActivity.USER_ID, employee.id);
		// startActivity(intent);
		// }
		// });
		if (employee.nickname != null) {
			mOrderEmployeeName.setText(employee.nickname);
		}
		if (isEmployee) {
			mOrderEmployerPhone.setVisibility(View.VISIBLE);
			mOrderEmployerPhone.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent intent = new Intent(
							Intent.ACTION_CALL,
							Uri.parse("tel:"
									+ mOrderInfoModel.publicOrder.employer.mobile_phone));
					startActivity(intent);
				}
			});
		} else {
			mOrderEmployeePhone.setVisibility(View.VISIBLE);
			mOrderEmployeePhone.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent intent = new Intent(Intent.ACTION_CALL, Uri
							.parse("tel:" + employee.mobile_phone));
					startActivity(intent);
				}
			});
		}
	}

	/**
	 * 游客模式，不显示订单状态
	 */
	private void setVisitor() {

		mOrderEmployeeView.setVisibility(View.GONE);
		mOrderStatusArrow.setVisibility(View.GONE);
		mOrderStatusView.setEnabled(false);
		mOrderBtnCancel.setVisibility(View.GONE);
		mOrderStatusView.setBackgroundColor(Color.parseColor("#eeeeee"));
		mOrderStatus.setText(getString(R.string.order_have_been_received));

	}

	/**
	 * 判断是否当前用户
	 */
	public boolean isEmp(SIMPLE_USER user) {
		if (user.id == SESSION.getInstance().uid) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public void onRefresh(int id) {
		// TODO Auto-generated method stub
		mOrderInfoModel.get(mOrderId);
	}

	@Override
	public void onLoadMore(int id) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		unregisterReceiver(mMessageReceiver);

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == COMMENT_SEND) {
			if (data != null) {
				ORDER_INFO order = (ORDER_INFO) data
						.getSerializableExtra(O2OMobileAppConst.ORDERINFO);
				setOrderDetailView(order);
			}
		} else {
			// Todo
		}
	}

	public void hidePayView() {
		AnimationUtil.backAnimationFromBottom(mOrderPlayOrderView);
		mOrderPlayOrderView.setVisibility(View.GONE);
		AnimationUtil.backAnimation(mOrderPlayButtonView);
		mOrderPlayButtonView.setVisibility(View.GONE);
		Handler mHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				super.handleMessage(msg);
				mOrderPlay.setVisibility(View.GONE);
				mOrderBtnCancel.setVisibility(View.VISIBLE);
			}
		};
		mHandler.sendEmptyMessageDelayed(0, 200);
	}

	Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			super.handleMessage(msg);
	
		}
	};
	private LinearLayout mShow_payway;
	private TextView mPayway;
	private TextView mEstimate_distance;
	private TextView mReal_distance;

	// private TTSController ttsManager;

	@Override
	protected void onNewIntent(Intent intent) {
		// 如果要统计Push引起的用户使用应用情况，请实现本方法，且加上这一个语�?
		setIntent(intent);
		handleIntent(intent);
	}

	private void handleIntent(Intent intent) {

		mOrderId = intent.getIntExtra(ORDER_ID, 0);
		mOrderInfoModel.get(mOrderId);
	}

	public void registerMessageReceiver() {
		mMessageReceiver = new MessageReceiver();
		IntentFilter filter = new IntentFilter();
		filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
		filter.addAction(MESSAGE_RECEIVED_ACTION_TITLE);
		registerReceiver(mMessageReceiver, filter);
	}

	public class MessageReceiver extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			if (MESSAGE_RECEIVED_ACTION_TITLE.equals(intent.getAction())) {
				String title = intent.getStringExtra("title");
				System.out.println("title" + title);
				if (title != null && title.equals("refresh")) {
					if (mOrderInfoModel != null) {
						mOrderInfoModel.get(mOrderId);
					}

				}

			}
		}
	}

	@Override
	protected void onResume() {
		isForeground = true;
		super.onResume();
	}

	@Override
	protected void onPause() {
		isForeground = false;
		super.onPause();
	}



	// 计费
	public float payFor(float distant) {
		BigDecimal a = new BigDecimal(distant).setScale(0,BigDecimal.ROUND_HALF_UP);

		float money = mShared1.getFloat("start_price", (float) 5.00);
		float per_distant = mShared1.getFloat("per_distant", (float) 2.00);
		float start_distant = mShared1.getFloat("start_distant", (float) 2.00);

		if (a.floatValue() < start_distant) {

		} else {

			money = money + (a.floatValue() - start_distant) * per_distant;

		}
		return money;
	}

	@Override
	public void onLocationChanged(Location arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProviderDisabled(String arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProviderEnabled(String arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onLocationChanged(AMapLocation arg0) {
		if (arg0.getLatitude() > 1 && arg0.getLongitude() > 1) {
			startPoint = new LatLonPoint(arg0.getLatitude(),
					arg0.getLongitude());
			final RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(
					startPoint, endPoint);

			DriveRouteQuery query = new DriveRouteQuery(fromAndTo,
					RouteSearch.DrivingMultiStrategy, null, null, "");// 第一个参数表示路径规划的起点和终点，第二个参数表示驾车模式，第三个参数表示途经点，第四个参数表示避让区域，第五个参数表示避让道路
			routeSearch.calculateDriveRouteAsyn(query);// 异步路径规划驾车模式查询
		}
		
		
		
		
	}

	@Override
	public void onBusRouteSearched(BusRouteResult arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onDriveRouteSearched(DriveRouteResult result, int rCode) {
		if (rCode == 0) {
			if (result != null && result.getPaths() != null
					&& result.getPaths().size() > 0) {
				driveRouteResult = result;
				DrivePath drivePath = driveRouteResult.getPaths().get(0);
				
					distant = drivePath.getDistance() / 1000;
					if (distant >= 0) {
						float price = payFor(distant);
									showOrderPriceDialog(price + "", String.valueOf(distant));

								} else {
									Toast.makeText(D1_OrderActivity.this, "起点和终点太短，有作弊嫌疑，该订单不能完成",
											2000).show();
								}
				

			} else {
				// ToastUtil.show(RouteActivity.this, R.string.no_result);
			}

		}
		
			
		
	}

	@Override
	public void onWalkRouteSearched(WalkRouteResult arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}
}
